from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from .base import TimedBaseModel


class Product(TimedBaseModel):
    __tablename__ = "product"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    first_name: Mapped[str] = mapped_column(String(255))
    last_name: Mapped[str] = mapped_column(String(255))
    year: Mapped[int]
    month: Mapped[int]
    day: Mapped[int]
    gender: Mapped[str] = mapped_column(String(255))
    house_num: Mapped[str] = mapped_column(String(255))
    street_name: Mapped[str] = mapped_column(String(255))
    post_code: Mapped[str] = mapped_column(String(255))
    login: Mapped[str] = mapped_column(String(255), unique=True)
    password: Mapped[str] = mapped_column(String(255))
    email: Mapped[str] = mapped_column(String(255), unique=True)
    email_password: Mapped[str | None] = mapped_column(String(255))
    cpf: Mapped[str | None] = mapped_column(String(255))
    docs: Mapped[str | None] = mapped_column(String(255))
    category = relationship("Category", back_populates="products")
    category_id: Mapped[int] = mapped_column(ForeignKey("category.id"))
    order = relationship("Order", back_populates="products")
    order_id: Mapped[int] = mapped_column(ForeignKey("order.id"), nullable=True)

    def __repr__(self):
        return f"<Аккаунт №{self.id} {self.login}>"

    def __str__(self):
        return self.__repr__()
